package com.css.fxfzypg.modules.saresults.repository.impl;

import com.css.fxfzypg.modules.saresults.entity.DzqhApAsicMapEntity;
import com.css.fxfzypg.modules.saresults.entity.DzqhQpBasicMapEntity;
import com.css.fxfzypg.modules.saresults.entity.DzqhXqhBasicMapEntity;
import com.css.fxfzypg.modules.saresults.repository.XqhResultsRepository;
import com.css.fxfzypg.modules.saresults.vo.SaResultsHlVo;
import com.css.fxfzypg.util.PlatformObjectUtils;
import com.css.fxfzypg.zcpt.sys.service.SysAreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Repository
public class XqhResultsRepositoryImpl implements XqhResultsRepository {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Resource
    private SysAreaService sysAreaService;


    @Override
    public List<DzqhXqhBasicMapEntity> queryProjectByProjectName(String projectName) {
        String sql = "select * from dzqh_xqh_basic_map where is_delete = '0' and sub_status='1' and update_status='0' and project_name='" + projectName + "'";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class));
    }

    @Override
    public DzqhXqhBasicMapEntity queryDzqhXqpBasicMap(String projectId) {
        String sql = "select * from dzqh_xqh_basic_map where project_id = '" + projectId + "'";
        try {
            return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class));
        } catch (DataAccessException e) {
            return null;
        }
    }

    @Override
    public void updateReason(String updateReason, String projectId) {
        String sql = "update dzqh_xqh_basic_map set status='1',update_reason=? where project_id=?";
        jdbcTemplate.update(sql, updateReason, projectId);
    }

    @Override
    public void updateApprovalStatus(String status,String projectId, String reviewComments, String approvalStatus, String userName, String orgName, Date approvalTime) {
        String sql = "update dzqh_xqh_basic_map set status=?, approval_status= ?, review_comments = ?,update_status='0',approval_user=?,approval_time=?,approval_org=? where original_data_id = ?";
        jdbcTemplate.update(sql,status,approvalStatus,reviewComments,userName,approvalTime,orgName,projectId);
    }

    @Override
    public void deleteXqpAsicMap(String projectId) {
        String sql = "delete from dzqh_xqh_basic_map where project_id=?";
        jdbcTemplate.update(sql, projectId);
    }

    @Override
    public void updateDzqhXqhBasicMap(DzqhXqhBasicMapEntity it) {
        String sql = "update dzqh_xqh_basic_map set project_name= :projectName,survey= :survey,cp_file= :cpFile,administrative_region= :administrativeRegion," +
                "sub_date= :subDate,review_unit= :reviewUnit,undertaker= :undertaker,client= :client,cp_number= :cpNumber,geophysical_survey_line= :geophysicalSurveyLine," +
                "evaluation_results= :evaluationResults,registration_unit= :registrationUnit,rs_map= :rsMap,new_fp_map= :newFpMap,nfss_map= :nfssMap,reed_map= :reedMap,nfeed_map= :nfeedMap," +
                "psa_map= :psaMap,bh_map= :bhMap,sepz= :sepz,sepz2= :sepz2,sepz10= :sepz10,sepz63= :sepz63,saghd_map= :saghdMap,bd_map= :bdMap,egp_map= :egpMap,egud_map= :egudMap,periodic_point= :periodicPoint," +
                "rs_value= :rsValue,upload_report= :uploadReport,sub_status= :subStatus,update_user= :updateUser,update_time= :updateTime,update_reason= :updateReason,review_comments= :reviewComments," +
                "approval_user= :approvalUser,longitude= :longitude,latitude= :latitude,sagh_evaluation= :saghEvaluation,lp_picture= :lpPicture,geological_profile_image = :geologicalProfileImage,update_detailed_information = :updateDetailedInformation,compare = :compare,"+
                "geom_text= :geomText where project_id = :projectId";
        SqlParameterSource source = new BeanPropertySqlParameterSource(it);
        namedParameterJdbcTemplate.update(sql, source);
    }

    @Override
    public void updateOldStatus(String projectId,String updateReason) {
        String sql = "update dzqh_xqh_basic_map set status='2', approval_status= '1' ,update_reason= ? where project_id = ?";
        jdbcTemplate.update(sql, updateReason,projectId);
    }

    @Override
    public void saveDzqhXqhBasicMap(DzqhXqhBasicMapEntity it) {
//        jdbcTemplate.update("insert into dzqh_xqh_basic_map(project_id,original_data_id,project_name,survey,cp_file,administrative_region,sub_date,review_unit,undertaker,client," +
//                        "cp_number,geophysical_survey_line,evaluation_results,registration_unit,rs_map,new_fp_map,nfss_map,reed_map,nfeed_map,psa_map,bh_map,sepz,sepz2,sepz10,sepz63," +
//                        "saghd_map,bd_map,egp_map,egud_map,periodic_point,rs_value,upload_report,sub_status,status,approval_status,delete_reason,registrant,create_user,create_time," +
//                        "is_delete,update_reason,review_comments,update_status,approval_user,approval_org,longitude,latitude,sagh_evaluation,lp_picture,province_id,org_id,model,geological_profile_image,update_detailed_information,log_id,compare"+
//                        ") " +
//                        "values ('"+it.getProjectId()+"','"+it.getOriginalDataId()+"','"+it.getProjectName()+"','"+it.getSurvey()+"'," +
//                "                '"+it.getCpFile()+"','"+it.getAdministrativeRegion()+"','"+it.getSubDate()+"','"+it.getReviewUnit()+"','"+it.getUndertaker()+"','"+it.getClient()+"','"+it.getCpNumber()+"','"+it.getGeophysicalSurveyLine()+"','"+it.getEvaluationResults()+"'," +
//                "                '"+it.getRegistrationUnit()+"','"+it.getRsMap()+"','"+it.getNewFpMap()+"','"+it.getNfssMap()+"','"+it.getReedMap()+"','"+it.getNfeedMap()+"','"+it.getPsaMap()+"','"+it.getBhMap()+"','"+it.getSepz()+"','"+it.getSepz2()+"','"+it.getSepz10()+"','"+it.getSepz63()+"','"+it.getSaghdMap()+"','"+it.getBdMap()+"'," +
//                "                '"+it.getEgpMap()+"','"+it.getEgudMap()+"','"+it.getPeriodicPoint()+"','"+it.getRsValue()+"','"+it.getUploadReport()+"','"+it.getSubStatus()+"','"+it.getStatus()+"','"+it.getApprovalStatus()+"','"+it.getDeleteReason()+"','"+it.getRegistrant()+"'," +
//                "                '"+it.getCreateUser()+"','"+it.getCreateTime()+"','"+it.getIsDelete()+"','"+it.getUpdateReason()+"','"+it.getReviewComments()+"','"+it.getUpdateStatus()+"','"+it.getApprovalUser()+"'," +
//                "                '"+it.getApprovalOrg()+"','"+it.getLongitude()+"','"+it.getLatitude()+"','"+it.getSaghEvaluation()+"','"+it.getLpPicture()+"','"+it.getProvinceId()+"','"+it.getOrgId()+"','"+it.getModel()+"','"+it.getGeologicalProfileImage()+"','"+it.getUpdateDetailedInformation()+"','"+it.getLogId()+"','"+it.getCompare()+"'," +
//                "                )");
        jdbcTemplate.update("insert into dzqh_xqh_basic_map  (project_id,original_data_id,project_name,survey,cp_file,administrative_region,sub_date,review_unit,undertaker,client,cp_number,geophysical_survey_line,evaluation_results,registration_unit,rs_map,new_fp_map,nfss_map,reed_map,nfeed_map,psa_map,bh_map,sepz63,sepz10,sepz2,saghd_map,bd_map,egp_map,egud_map,periodic_point,rs_value,upload_report,sub_status,status,approval_status,delete_reason,registrant,create_user,create_time,update_user,update_time,is_delete,update_reason,review_comments,update_status,approval_user,approval_time,approval_org,longitude,latitude,sagh_evaluation,lp_picture,province_id,org_id,model,sepz,geom_text,geological_profile_image,update_detailed_information,log_id,compare ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )",
                it.getProjectId(),it.getOriginalDataId(),it.getProjectName(),it.getSurvey(),it.getCpFile(),it.getAdministrativeRegion(),it.getSubDate(),it.getReviewUnit(),it.getUndertaker(),it.getClient(),it.getCpNumber(),it.getGeophysicalSurveyLine(),it.getEvaluationResults(),it.getRegistrationUnit(),it.getRsMap(),it.getNewFpMap(),it.getNfssMap(),it.getReedMap(),it.getNfeedMap(),it.getPsaMap(),it.getBhMap(),it.getSepz63(),it.getSepz10(),it.getSepz2(),it.getSaghdMap(),it.getBdMap(),it.getEgpMap(),it.getEgudMap(),it.getPeriodicPoint(),it.getRsValue(),it.getUploadReport(),it.getSubStatus(),it.getStatus(),it.getApprovalStatus(),it.getDeleteReason(),it.getRegistrant(),it.getCreateUser(),it.getCreateTime(),it.getUpdateUser(),it.getUpdateTime(),it.getIsDelete(),it.getUpdateReason(),it.getReviewComments(),it.getUpdateStatus(),it.getApprovalUser(),it.getApprovalTime(),it.getApprovalOrg(),it.getLongitude(),it.getLatitude(),it.getSaghEvaluation(),it.getLpPicture(),it.getProvinceId(),it.getOrgId(),it.getModel(),it.getSepz(),it.getGeomText(),it.getGeologicalProfileImage(),it.getUpdateDetailedInformation(),it.getLogId(),it.getCompare());
    }

    @Override
    public HashMap<String, Object> getXqhResultsProject(DzqhXqhBasicMapEntity xqhBasicMapEntity, int page, int size,String orgId,String provinceId,String userId,String geom) {
        StringBuilder sql = new StringBuilder("select * from dzqh_xqh_basic_map where sub_status='1' and update_status='0'");
        if (xqhBasicMapEntity.getRole().equals("3")){
            sql.append(" and is_delete='0' and create_user='"+userId+"'");
        }
        if (xqhBasicMapEntity.getRole().equals("1")){
            sql.append(" and province_id='"+provinceId+"'");
        }
        if (xqhBasicMapEntity.getRole().equals("2")){
            //sql.append(" and province_id='"+provinceId +"' or org_id='"+orgId+"'");
            sql.append(" and (province_id='"+provinceId +"' or org_id='"+orgId+"')");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getProjectName())) {
            sql.append(" and project_name like '%" + xqhBasicMapEntity.getProjectName() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getLongitude())) {
            sql.append(" and longitude >= '"+xqhBasicMapEntity.getLongitude()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getEndLongitude())){
            sql.append(" and longitude <= '"+xqhBasicMapEntity.getEndLongitude()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getLatitude())) {
            sql.append(" and latitude >= '"+xqhBasicMapEntity.getLatitude()+"'");
        }
        if(!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getEndLatitude())){
            sql.append(" and latitude <= '"+xqhBasicMapEntity.getEndLatitude()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getApprovalStatus())) {
            sql.append(" and approval_status ='" + xqhBasicMapEntity.getApprovalStatus()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getReviewUnit())) {
            sql.append(" and review_unit like '%" + xqhBasicMapEntity.getReviewUnit() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getStatus())) {
            sql.append(" and status = '" + xqhBasicMapEntity.getStatus()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getAdministrativeRegion())) {
            sql.append(" and administrative_region= '" + xqhBasicMapEntity.getAdministrativeRegion()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getUndertaker())) {
            sql.append(" and undertaker like '%" + xqhBasicMapEntity.getUndertaker() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getRegistrant())) {
            sql.append(" and registrant like '%"+xqhBasicMapEntity.getRegistrant()+"%'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getRegistrationUnit())) {
            sql.append(" and registration_unit like '%" + xqhBasicMapEntity.getRegistrationUnit() + "%'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getCreateStartTime())) {
            sql.append(" and date(create_time) >= '"+xqhBasicMapEntity.getCreateStartTime()+"'");
        }
        if( !PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getCreateEndTime())){
            sql.append(" and date(create_time) <= '"+xqhBasicMapEntity.getCreateEndTime()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getSubStartTime())) {
            sql.append(" and sub_date >= '" + xqhBasicMapEntity.getSubStartTime()+"'");
        }
        if(!PlatformObjectUtils.isEmpty(xqhBasicMapEntity.getSubEndTime())){
            sql.append(" and sub_date <= '" + xqhBasicMapEntity.getSubEndTime()+"'");
        }

        //地图圈选范围查询
        if (!PlatformObjectUtils.isEmpty(geom)) {
            //项目位置上传文件空间位置相交
            sql.append(" and geom_text is not null and geom_text!='' and ST_Intersects(st_geometryfromtext(geom_text,4490),st_geometryfromtext('"+geom+"',4490))");
            //项目位置经纬度相交查询
            //sql.append(" and ST_Intersects(st_geometryfromtext('POINT(' || longitude || ' ' || latitude || ')',4490),st_geometryfromtext('"+geomText+"',4490))");
        }
        sql.append(" group by project_id");
        StringBuilder orderSql = new StringBuilder(" order by create_time desc");
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class)).size();
        StringBuilder limitSql = new StringBuilder(" limit " + size + " offset " + (page - 1) * size);
        sql.append(orderSql).append(limitSql);
        List<DzqhXqhBasicMapEntity> xqhBasicMapEntityList = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class));
        for (DzqhXqhBasicMapEntity xqhMap : xqhBasicMapEntityList) {
            String region = xqhMap.getAdministrativeRegion();
            xqhMap.setAdministrativeRegion(sysAreaService.getAreaNameByAreaId(region));
        }
        HashMap<String, Object> resultMap = new HashMap();
        resultMap.put("total", total);
        resultMap.put("rows", xqhBasicMapEntityList);
        return resultMap;
    }

    @Override
    public HashMap<String, Object> getXqhResultsHl(SaResultsHlVo saResultsHlVo, int page, int size,String orgId,String provinceId,String userId,String geom) {
        StringBuilder sql = new StringBuilder("select dxbm.* from dzqh_xqh_basic_map dxbm \n" +
                "left join (select *,array_to_string(array (select unnest(array_agg(hl_longitude))),',') as longitude,array_to_string(array (select unnest(array_agg(hl_latitude))),',') as latitude from dzqh_ap_crux_layer_pf group by pf_id) as daclp on daclp.project_id = dxbm.project_id \n" +
                "left join dzqh_ap_crux_sd dacsd on dacsd.project_id=dxbm.project_id \n" +
                "left join dzqh_ap_crux_sc dacsc on dacsc.project_id=dxbm.project_id \n" +
                "left join dzqh_ap_crux_sd dacs on dacs.project_id= dxbm.project_id \n" +
                "where dxbm.sub_status='1' and dxbm.update_status='0'");
        if (saResultsHlVo.getRole().equals("3")){
            sql.append(" and dxbm.is_delete='0' and dxbm.create_user='"+userId+"'");
        }
        if (saResultsHlVo.getRole().equals("1")){
            sql.append(" and dxbm.province_id='"+provinceId+"'");
        }
        if (saResultsHlVo.getRole().equals("2")){
            //sql.append(" and dxbm.province_id='"+provinceId +"' or dxbm.org_id='"+orgId+"'");
            sql.append(" and (dxbm.province_id='"+provinceId +"' or dxbm.org_id='"+orgId+"')");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getProjectName())) {
            sql.append(" and dxbm.project_name like '%" + saResultsHlVo.getProjectName()+"%'");
        }

        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getHlLongitude()) && !PlatformObjectUtils.isEmpty(saResultsHlVo.getEndHlLongitude())) {
            sql.append(" and daclp.hl_longitude between '"+saResultsHlVo.getHlLongitude()+"' and '"+saResultsHlVo.getEndHlLongitude()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getHlLatitude()) && !PlatformObjectUtils.isEmpty(saResultsHlVo.getEndHlLatitude())) {
            sql.append(" and daclp.hl_latitude between '"+saResultsHlVo.getHlLatitude()+"' and '"+saResultsHlVo.getEndHlLatitude()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getBdosSample())) {
            sql.append(" and dacsd.bdos_sample = '" + saResultsHlVo.getBdosSample()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getApprovalStatus())) {
            sql.append(" and dxbm.approval_status ='" + saResultsHlVo.getApprovalStatus()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getStatus())) {
            sql.append(" and dxbm.status = '" + saResultsHlVo.getStatus()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getLongitude()) && !PlatformObjectUtils.isEmpty(saResultsHlVo.getEndLongitude())) {
            sql.append(" and dxbm.longitude between '"+saResultsHlVo.getLongitude()+"' and '"+saResultsHlVo.getEndLongitude()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getLatitude()) && !PlatformObjectUtils.isEmpty(saResultsHlVo.getEndLatitude())) {
            sql.append(" and dxbm.latitude between '"+saResultsHlVo.getLatitude()+"' and '"+saResultsHlVo.getEndLatitude()+"'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getGeotechnicalName())) {
            sql.append(" and dacs.geotechnical_name like '%" + saResultsHlVo.getGeotechnicalName()+"%'");
        }
        if (!PlatformObjectUtils.isEmpty(saResultsHlVo.getFieldType())) {
            sql.append(" and dacsc.field_type = '" + saResultsHlVo.getFieldType()+"'");
        }
        //有孔位信息
        sql.append(" and daclp.project_id is not null and daclp.hl_longitude is not null and daclp.hl_latitude is not null");
        //地图圈选范围查询
        if (!PlatformObjectUtils.isEmpty(geom)) {
            //项目信息相交
            //sql.append(" and dxbm.geom_text is not null and dxbm.geom_text!='' and ST_Intersects(st_geometryfromtext(dxbm.geom_text,4490),st_geometryfromtext('"+geomText+"',4490))");
            //孔位信息相交
            sql.append(" and ST_Intersects(st_geometryfromtext('POINT(' || daclp.hl_longitude || ' ' || daclp.hl_latitude || ')',4490),st_geometryfromtext('"+geom+"',4490))");
        }

        StringBuilder orderSql = new StringBuilder(" group by dxbm.project_id order by dxbm.create_time desc");
        sql.append(orderSql);
        Integer total = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class)).size();
        StringBuilder limitSql = new StringBuilder(" limit " + size + " offset " + (page - 1) * size);
        sql.append(limitSql);
        List<DzqhXqhBasicMapEntity> xqhBasicMapEntityList = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class));
        for (DzqhXqhBasicMapEntity xqhMap : xqhBasicMapEntityList) {
            String region = xqhMap.getAdministrativeRegion();
            xqhMap.setAdministrativeRegion(sysAreaService.getAreaNameByAreaId(region));
        }
        HashMap<String, Object> resultMap = new HashMap();
        resultMap.put("total", total);
        resultMap.put("rows", xqhBasicMapEntityList);
        return resultMap;
    }

    @Override
    public List<DzqhXqhBasicMapEntity> queryNotSubmitted(String userId) {
        String sql = "select * from dzqh_xqh_basic_map where sub_status = '0' and create_user =?";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class),userId);
    }

    @Override
    public List<DzqhXqhBasicMapEntity> queryAllProject() {
        String sql = "select * from dzqh_xqh_basic_map where is_delete = '0' and sub_status='1' and update_status='0'";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class));
    }

    @Override
    public void tombstoneApAsicMap(String projectId, String deleteReason) {
        String sql = "update dzqh_xqh_basic_map set delete_reason= ?, approval_status='1',status = 3 where project_id = ?";
        jdbcTemplate.update(sql,deleteReason,projectId);
    }

    @Override
    public void updateDzqhXqhAsicMapStatus(String projectId, String deleteReason, String status) {
        String sql = "update dzqh_xqh_basic_map set delete_reason= ?, status = ? where project_id = ?";
        jdbcTemplate.update(sql, deleteReason,status,projectId);
    }

    @Override
    public void approvalUserDelete(String projectId, String reviewComments, String approvalStatus, String status, String isDelete, String userName, String orgName, Timestamp currentTimestamp) {
        String sql = "update dzqh_xqh_basic_map set approval_status=?,status=?,is_delete=?,review_comments=?,approval_user=?,approval_time=?,approval_org=? where project_id=?";
        jdbcTemplate.update(sql,approvalStatus,status,isDelete,reviewComments,userName,currentTimestamp,orgName,projectId);
    }

    @Override
    public void deleteDzqhXqAsicMap(String projectId, String deleteReason) {
        String sql = "update dzqh_xqh_basic_map set delete_reason= ?,status='3', approval_status='1' where project_id = ?";
        jdbcTemplate.update(sql, deleteReason, projectId);
    }

    @Override
    public void auditFailed(String status, String projectId, String reviewComments, String approvalStatus, String userName, String orgName, Timestamp currentTimestamp) {
        String sql = "update dzqh_xqh_basic_map set status=?, approval_status= ?, review_comments = ?,update_status='0',approval_user=?,approval_time=?,approval_org=? where project_id = ?";
        jdbcTemplate.update(sql,status,approvalStatus,reviewComments,userName,currentTimestamp,orgName,projectId);
    }

    @Override
    public void updateStatus(DzqhXqhBasicMapEntity entity, String projectId) {
        String sql = "update dzqh_xqh_basic_map set update_reason = '"+entity.getUpdateReason()+"',status = '"+entity.getStatus()+"',approval_status = '"+entity.getApprovalStatus()+"' where project_id = '"+projectId+"'";
        jdbcTemplate.update(sql);
    }

    @Override
    public DzqhXqhBasicMapEntity queryDzqhXqpBasicMapByOldId(String originalDataId) {
        String sql = "select * from dzqh_xqh_basic_map where original_data_id = '" + originalDataId + "";
        try {
            return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(DzqhXqhBasicMapEntity.class));
        } catch (DataAccessException e) {
            return null;
        }
    }
}
